const http = require('http');
const url = require('url');

let username = process.argv[2];
let password = process.argv[3];
let userInfo = {username:username,password:password};
let userStr = JSON.stringify(userInfo);
let reqUrl = 'http://localhost:8081/';
let options = url.parse(reqUrl);
options.method = "POST";
let reqObj = http.request(options, (res) => {  //请求的数据会放到reqObj里
    let str = '';
    res.on('data',chunk => {
        str += chunk;
    })
    res.on('end',() => {
        console.log(str);
    })
})
reqObj.write(userStr);//向请求体写入数据
reqObj.end();